package com.superman.supermarket.client.view.collection;

import java.util.List;
import java.util.Map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.mvp.IPageViewPresenter;
import com.superman.mvpframe.client.widget.pulltorefresh.IPullToRefreshView;
import com.superman.mvpframe.client.widget.pulltorefresh.PullToRefreshViewAbstractImpl;
import com.superman.supermarket.client.composite.collection.CollectionModule;

/**
 * 收藏ui实现类
 * 
 * @author superman
 * @version 2018年8月2日下午5:20:58
 */
public class CollectionViewImpl extends PullToRefreshViewAbstractImpl implements CollectionView {
	interface CollectionViewImplUiBinder extends UiBinder<Widget, CollectionViewImpl> {
	}

	private static CollectionViewImplUiBinder uiBinder = GWT.create(CollectionViewImplUiBinder.class);

	private CollectionViewPresenter presenter;

	@UiField
	FlowPanel wrapperpanel, listpanel;

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年8月7日 上午10:57:03
	 */
	public CollectionViewImpl() {
		this.initWidget(uiBinder.createAndBindUi(this));
	}

	@UiHandler("clearbtn")
	void clearInvalidSkus(ClickEvent event) {
		presenter.clean();
	}

	@Override
	public IPullToRefreshView getPullToRefreshView() {
		return this;
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub

	}

	@Override
	public void setDataListDivId(String id) {
		listpanel.getElement().setId(id);
	}

	@Override
	public void setListData(List<Map<String, Object>> list) {
		for (Map<String, Object> map : list) {
			CollectionModule collectionModule = new CollectionModule();
			collectionModule.setData(map);
			listpanel.add(collectionModule);
		}
	}

	@Override
	public void setMeScrollDivId(String id) {
		wrapperpanel.getElement().setId(id);
	}

	@Override
	public void setPageViewPresenter(IPageViewPresenter presenter) {
		this.presenter = (CollectionViewPresenter) presenter;
	}

}
